package com.hsc.yalebao.weight.viewpager;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout.LayoutParams;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class BannerViewPager extends LinearLayout
  implements ViewPager.OnPageChangeListener
{
  private int LOOP = 200;
  private int LOOP_WAIT = 201;
  private int currentPosition;
  private FrameLayout fl_banner_viewpager;
  private Handler handler = new Handler()
  {
    public void handleMessage(Message paramAnonymousMessage)
    {
      if ((paramAnonymousMessage.what == BannerViewPager.this.LOOP) && (BannerViewPager.this.imageViews.size() != 0))
      {
        if (!BannerViewPager.this.isScrolling)
        {
          i = 1 + BannerViewPager.this.imageViews.size();
          j = (1 + BannerViewPager.this.currentPosition) % BannerViewPager.this.imageViews.size();
          BannerViewPager.this.vp_banner.setCurrentItem(j, true);
          if (j == i)
            BannerViewPager.this.vp_banner.setCurrentItem(1, false);
        }
        BannerViewPager.this.releaseTime = System.currentTimeMillis();
        BannerViewPager.this.handler.removeCallbacks(BannerViewPager.this.runnable);
        BannerViewPager.this.handler.postDelayed(BannerViewPager.this.runnable, BannerViewPager.this.scrolltime);
      }
      while ((paramAnonymousMessage.what != BannerViewPager.this.LOOP_WAIT) || (BannerViewPager.this.imageViews.size() == 0))
      {
        int i;
        int j;
        return;
      }
      BannerViewPager.this.handler.removeCallbacks(BannerViewPager.this.runnable);
      BannerViewPager.this.handler.postDelayed(BannerViewPager.this.runnable, BannerViewPager.this.scrolltime);
    }
  };
  private List<ImageView> imageViews = new ArrayList();
  private ImageView[] indicators;
  private boolean isLoop = true;
  private boolean isScrolling = false;
  private boolean isWheel = true;
  private List<String> list = new ArrayList();
  private LinearLayout ll_scroll_banner_indicator;
  private OnItemClickListener onItemClickListener;
  private long releaseTime = 0L;
  final Runnable runnable = new Runnable()
  {
    public void run()
    {
      if ((BannerViewPager.this.getContext() != null) && (BannerViewPager.this.isWheel))
      {
        if (System.currentTimeMillis() - BannerViewPager.this.releaseTime > -500 + BannerViewPager.this.scrolltime)
          BannerViewPager.this.handler.sendEmptyMessage(BannerViewPager.this.LOOP);
      }
      else
        return;
      BannerViewPager.this.handler.sendEmptyMessage(BannerViewPager.this.LOOP_WAIT);
    }
  };
  private int scrolltime = 3000;
  private ViewPagerAdapter viewPagerAdapter;
  private SetingScrollBanner vp_banner;

  public BannerViewPager(Context paramContext)
  {
    super(paramContext);
    init(paramContext);
  }

  public BannerViewPager(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    init(paramContext);
  }

  private void init(Context paramContext)
  {
    setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
    View localView = View.inflate(paramContext, 2130903228, null);
    this.fl_banner_viewpager = ((FrameLayout)localView.findViewById(2131100364));
    this.vp_banner = ((SetingScrollBanner)localView.findViewById(2131100365));
    this.ll_scroll_banner_indicator = ((LinearLayout)localView.findViewById(2131100366));
    addView(localView);
  }

  private void setIndicator(int paramInt)
  {
    for (int i = 0; ; i++)
    {
      if (i >= this.indicators.length)
      {
        if (this.indicators.length > paramInt)
          this.indicators[paramInt].setBackgroundResource(2130838125);
        return;
      }
      this.indicators[i].setBackgroundResource(2130838124);
    }
  }

  public void hideBanner()
  {
    this.fl_banner_viewpager.setVisibility(8);
  }

  public void hideIndicator()
  {
    this.ll_scroll_banner_indicator.setVisibility(8);
  }

  public boolean isLoop()
  {
    return this.isLoop;
  }

  public boolean isWheel()
  {
    return this.isWheel;
  }

  public void onPageScrollStateChanged(int paramInt)
  {
    if (paramInt == 1)
    {
      this.isScrolling = true;
      return;
    }
    if (paramInt == 0)
    {
      if (this.vp_banner != null)
        this.vp_banner.setScrollable(true);
      this.releaseTime = System.currentTimeMillis();
      this.vp_banner.setCurrentItem(this.currentPosition, false);
    }
    this.isScrolling = false;
  }

  public void onPageScrolled(int paramInt1, float paramFloat, int paramInt2)
  {
  }

  public void onPageSelected(int paramInt)
  {
    int i = -1 + this.imageViews.size();
    int j = paramInt;
    this.currentPosition = paramInt;
    if (this.isLoop)
    {
      if (paramInt != 0)
        break label50;
      this.currentPosition = (i - 1);
    }
    while (true)
    {
      j = -1 + this.currentPosition;
      setIndicator(j);
      return;
      label50: if (paramInt == i)
        this.currentPosition = 1;
    }
  }

  public void refreshData()
  {
    if (this.viewPagerAdapter != null)
      this.viewPagerAdapter.notifyDataSetChanged();
  }

  public void setData(List<ImageView> paramList, List<String> paramList1, OnItemClickListener paramOnItemClickListener)
  {
    setData(paramList, paramList1, paramOnItemClickListener, 0);
  }

  public void setData(List<ImageView> paramList, List<String> paramList1, OnItemClickListener paramOnItemClickListener, int paramInt)
  {
    this.onItemClickListener = paramOnItemClickListener;
    this.list = paramList1;
    this.imageViews.clear();
    if (paramList1.size() == 0)
    {
      this.fl_banner_viewpager.setVisibility(8);
      return;
    }
    if (paramList1.size() == 1)
    {
      setScrollable(false);
      this.isWheel = false;
      this.ll_scroll_banner_indicator.setVisibility(8);
      this.imageViews.add((ImageView)paramList.get(0));
      int i = paramList.size();
      this.indicators = new ImageView[i];
      if (this.isLoop)
        this.indicators = new ImageView[i - 2];
      this.ll_scroll_banner_indicator.removeAllViews();
    }
    for (int j = 0; ; j++)
    {
      if (j >= this.indicators.length)
      {
        this.viewPagerAdapter = new ViewPagerAdapter(null);
        setIndicator(0);
        this.vp_banner.setOffscreenPageLimit(3);
        this.vp_banner.setOnPageChangeListener(this);
        this.vp_banner.setAdapter(this.viewPagerAdapter);
        if ((paramInt < 0) || (paramInt > paramList.size()))
          paramInt = 0;
        if (this.isLoop)
          paramInt++;
        this.vp_banner.setCurrentItem(paramInt);
        return;
        Iterator localIterator = paramList.iterator();
        while (localIterator.hasNext())
        {
          ImageView localImageView = (ImageView)localIterator.next();
          this.imageViews.add(localImageView);
        }
        break;
      }
      View localView = View.inflate(getContext(), 2130903227, null);
      this.indicators[j] = ((ImageView)localView.findViewById(2131100363));
      this.ll_scroll_banner_indicator.addView(localView);
    }
  }

  public void setIndicatorCenter()
  {
    RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-2, -2);
    localLayoutParams.addRule(12);
    localLayoutParams.addRule(14);
    this.ll_scroll_banner_indicator.setLayoutParams(localLayoutParams);
  }

  public void setLoop(boolean paramBoolean)
  {
    this.isLoop = paramBoolean;
  }

  public void setScrollTime(int paramInt)
  {
    this.scrolltime = paramInt;
  }

  public void setScrollable(boolean paramBoolean)
  {
    this.vp_banner.setScrollable(paramBoolean);
  }

  public void setWheel(boolean paramBoolean)
  {
    this.isWheel = paramBoolean;
    this.isLoop = true;
    if (paramBoolean)
      this.handler.postDelayed(this.runnable, this.scrolltime);
  }

  public static abstract interface OnItemClickListener
  {
    public abstract void onItemClick(int paramInt);
  }

  private class ViewPagerAdapter extends PagerAdapter
  {
    private ViewPagerAdapter()
    {
    }

    public void destroyItem(ViewGroup paramViewGroup, int paramInt, Object paramObject)
    {
      paramViewGroup.removeView((View)paramObject);
    }

    public int getCount()
    {
      return BannerViewPager.this.imageViews.size();
    }

    public int getItemPosition(Object paramObject)
    {
      return -2;
    }

    public View instantiateItem(ViewGroup paramViewGroup, final int paramInt)
    {
      ImageView localImageView = (ImageView)BannerViewPager.this.imageViews.get(paramInt);
      if (BannerViewPager.this.onItemClickListener != null)
        localImageView.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View paramAnonymousView)
          {
            if (BannerViewPager.this.list.size() == 1)
            {
              BannerViewPager.this.onItemClickListener.onItemClick(0);
              return;
            }
            BannerViewPager.this.onItemClickListener.onItemClick(-1 + paramInt);
          }
        });
      paramViewGroup.addView(localImageView);
      return localImageView;
    }

    public boolean isViewFromObject(View paramView, Object paramObject)
    {
      return paramView == paramObject;
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.weight.viewpager.BannerViewPager
 * JD-Core Version:    0.6.2
 */